Expand description
This crate provides a rust abstraction over the features of the C library hidapi by signal11.
§Usage
This crate is on crates.io and can be
used by adding hidapi
to the dependencies in your project’s Cargo.toml
.
§Example
extern crate hidapi;
use hidapi::HidApi;
fn main() {
println!("Printing all available hid devices:");
match HidApi::new() {
Ok(api) => {
for device in api.device_list() {
println!("{:04x}:{:04x}", device.vendor_id(), device.product_id());
}
},
Err(e) => {
eprintln!("Error: {}", e);
},
}
}
For more usage examples, please take a look at the examples/
directory.
§Feature flags
linux-static-libusb
: uses statically linkedlibusb
backend on Linuxlinux-static-hidraw
: uses statically linkedhidraw
backend on Linux (default)linux-shared-libusb
: uses dynamically linkedlibusb
backend on Linuxlinux-shared-hidraw
: uses dynamically linkedhidraw
backend on Linuxlinux-native
: talks to hidraw directly without using thehidapi
C libraryillumos-static-libusb
: uses statically linkedlibusb
backend on Illumos (default)illumos-shared-libusb
: uses statically linkedhidraw
backend on Illumosmacos-shared-device
: enables shared access to HID devices on MacOSwindows-native
: talks to hid.dll directly without using thehidapi
C library
§Linux backends
On linux the libusb backends do not support DeviceInfo::usage()
and DeviceInfo::usage_page()
.
The hidraw backend has support for them, but it might be buggy in older kernel versions.
§MacOS Shared device access
Since hidapi
0.12 it is possible to open MacOS devices with shared access, so that multiple
HidDevice
handles can access the same physical device. For backward compatibility this is
an opt-in that can be enabled with the macos-shared-device
feature flag.
Structs§
- Device information. Use accessors to extract information about Hid devices.
hidapi
context.
Enums§
- The underlying HID bus type.